package com.example.backend.controller;

import com.example.backend.service.WordService;
import com.example.backend.util.Result;
import com.example.backend.util.ResultGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 词库相关控制器
 * @author 李月
 * @date 2022/5/2 14:03
 */
@RestController
@RequestMapping("/v1/words")
public class WordController {
    @Autowired
    private WordService wordService;

    /**
     * 查找单词
     * @param wordSpell 单词拼写
     * @return 根据结果返回不同信息
     */
    @GetMapping("/{wordSpell}")
    public Result findWord(@PathVariable("wordSpell") String wordSpell){
        if(wordService.findWord(wordSpell) != null){
            return ResultGenerator.genSuccessResult("查找单词成功", wordService.findWord(wordSpell));
        } else {
            return ResultGenerator.genFailResult("查找单词失败", null);
        }
    }
}
